package com.rj.core.validation;

import com.rj.util.VerifyUtils;
import com.rj.core.validation.constraints.NotEmpty;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

import java.util.Collection;
import java.util.Objects;

/**
 * @author YFX_RANLUBO
 */
public class NotEmptyValidator implements ConstraintValidator<NotEmpty, Object> {
    
    @Override
    public boolean isValid(Object value, ConstraintValidatorContext constraintValidatorContext) {
        if (Objects.nonNull(value)) {
            if (value instanceof String) {
                return VerifyUtils.notEmpty(value.toString());
            }
            if (value instanceof Collection collection) {
                return !VerifyUtils.isEmpty(collection);
            }
            return true;
        }
        return false;
    }


}